<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<th:block th:insert="~{include :: header('订阅')}"/>
<th:block th:insert="~{include :: bootstrap-select-css}"/>
<body>
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="subscribe-form">
                <div class="select-list">
                    <ul>
                        <li>
                            <label for="subBotUid">Bot： </label><input class="form-control" id="subBotUid"
                                                                       name="subBotUid"
                                                                       placeholder="BotUid"
                                                                       type="number"/>
                        </li>
                        <li>
                            <label for="subGroup">Group： </label><input class="form-control" id="subGroup"
                                                                        name="subGroup"
                                                                        placeholder="GroupUid"
                                                                        type="number"/>
                        </li>
                        <li>
                            <a class="btn btn-success btn-rounded btn-sm" onclick="searchPre()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="resetPre()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="container-div">
            <div class="row">
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<th:block th:insert="~{include :: footer}"/>
<th:block th:insert="~{include :: bootstrap-select-js}"/>
<script th:inline="javascript">
    const prefix = ctx + "data/warframe/subscribe";
    $(function () {
        const options = {
            url: prefix + "/list",
            modalName: "订阅",
            sortOrder: "desc",
            escape: true,
            showPageGo: true,
            rememberSelected: true,
            columns: [
                {
                    field: 'state',
                    radio: true
                },
                {
                    field: 'subBotUid',
                    title: 'Bot'
                },
                {
                    field: 'subGroup',
                    title: '订阅群组'
                },
                {
                    field: 'groupName',
                    title: '群组名称'
                },
                {
                    field: 'subUsers',
                    title: '订阅用户',
                    formatter: function (value, row) {
                        const actions = [];
                        actions.push('<table class="table table-bordered table-hover" style="margin-top: 0;"><thead><tr>' +
                            '<th><div class="th-inner">昵称</div></th>' +
                            '<th><div class="th-inner">账号</div></th>' +
                            '<th><div class="th-inner">订阅类型</div></th>' +
                            '<th><div class="th-inner">操作</div></th>' +
                            '</tr></thead><tbody>')
                        row.subUsers.forEach(function (subUser) {
                            let types = "";
                            subUser.typeList.forEach(
                                function (type) {
                                    if (type !== undefined)
                                        types += type.subscribeType + '</br>'
                                }
                            )
                            actions.push('<tr><td>' + subUser.userName + '</td><td>' + subUser.userId + '</td><td>' + types
                                + '</td><td> <a class="btn btn-warning btn-xs " href="javascript:void(0)"\n' +
                                '                                     onClick="$.operate.remove(' + row.userId + ',' + 300 + ',' + 450 + ')"><i\n' +
                                '                                    class="fa fa-remove"></i>移除订阅</a>'
                                + '</td></tr>')
                        })

                        actions.push('</tbody></table>')
                        return actions.join('');
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row) {
                        const actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.edit(' + row.subGroup + ',' + 300 + ',' + 450 + ')"><i class="fa fa-edit"></i>修改</a> ');
                        actions.push('<a class="btn btn-warning btn-xs " href="javascript:void(0)" onclick="$.operate.remove(' + row.subGroup + ',' + 300 + ',' + 450 + ')"><i class="fa fa-remove"></i>移除订阅</a> ');
                        return actions.join('');
                    }
                }

            ]
        };
        $.table.init(options);
    });

    function searchPre() {
        $.table.search('subscribe-form', 'bootstrap-table');
    }

    function resetPre() {
        $("#subscribe-form")[0].reset();
        $.table.search('subscribe-form', 'bootstrap-table');
    }

</script>

</body>
</html>